import React, { Component } from 'react'
import "./workinfo.scss"
import Header from '../../components/Header/header'
import Footer from '../../components/Footer/footer'
import {  getApiSignInfo , getApiGetWorkInfo } from "../../axios/api"
import { get, UrlSearch } from '../../axios/localstorage';
import { message } from 'antd'

export default class workinfo extends Component {

    state = {
        id:'',
        alert:false,
        data:{},
        livesign:[],
        ctype:1,
        videoUrl:"",
    }

    componentWillMount(){
        
        window.scroll(0,0);

        let id = UrlSearch('id');
        this.setState({
            id
        })

        this.getInfo(id);

        // this.getData(id);
    }

    gotoChangeCtype=(type)=>{
        this.setState({
            ctype:type
        })
    }

    getInfo=(id)=>{
        let param = {
            id:id,
            token:get('token')
        }

        getApiGetWorkInfo(param)
        .then( req =>{
            if(req.data.code === 1){
                let data = req.data.data;
                this.setState({
                    data
                })
            }
        }).catch( err =>{
            console.error(err);
        })
    }

    getData=(id)=>{
        let param = {
            id:id,
            token:get('token')
        }

        getApiSignInfo(param)
        .then( req =>{
            if(req.data.code === 1){
                let data = req.data.data;
                this.setState({
                    data,
                    livesign:[data.livesign],
                })
            }
        }).catch( err =>{
            console.error(err);
        })
    }

    gotoSignUp=()=>{
        if(!get('token')){
            message.info("请先登录");
            // this.gotoPage('/home')
            return false;
        }

        this.gotoPage('/productSignup?id='+this.state.id)

        // getApisetSign({
        //     token:get('token'),
        //     id:this.state.id
        // }).then( req =>{
        //     if(req.data.code === 1){
        //         this.setState({
        //             alert:true
        //         })

        //         this.getData(this.state.id)
        //     }else{
        //         message.info(req.data.msg);
        //     }
        // })
        
    }

    gotoPage=(page)=>{
        this.props.history.push(page);
    }

    gotoDataInfo=(id)=>{
        this.props.history.push('/signupinfo?id='+id);
        this.setState({id})
        this.getData(id);
        // this.getCate(id);
    }

    render() {
        return (
            <div className="workinfo">
                <Header />

                <div className='page1' style={{backgroundImage:"url('assets/img/zuopin.png')"}}>
                    <div className='pm'>
                        <div className="cleft">
                            <img className="img" alt="" src="assets/imgs/dingwei.png" />
                            <p className="p_point" onClick={()=>{
                                if(get('type')){
                                    this.gotoPage('/home')
                                    // this.gotoPage('/index')
                                  }else{
                                    this.gotoPage('/home')
                                  }
                            }}>首页</p>
                            <img className="icon" alt="" src="assets/img/xiaji.png" />
                            <p className="p_point" onClick={()=>{this.gotoPage('/works')}}>作品展示</p>
                            <img className="icon" alt="" src="assets/img/xiaji.png" />
                            <p>作品详情</p>
                        </div>
                        <div className='name'>
                            <img alt="" src="assets/img/zuopinzhanshi.png" />
                            <h2>作品展示</h2>
                            <p>优秀作品，海量观看</p>
                        </div>

                        <div className='info' >
                            <div className='imgBox' style={{backgroundImage:"url('"+this.state.data.image+"')"}}></div>
                            <div className='cinfo'>
                                <h2>{this.state.data.title}</h2>
                                <div className='ctext'>{this.state.data.introduction}</div>
                                <div className='ctime'>
                                    <div className='avatar' style={{backgroundImage:"url('"+this.state.data.avatar+"')"}}></div>
                                    <p>{this.state.data.username}</p>
                                    <h4>专家打分：<span>{this.state.data.fraction} 分</span></h4>
                                    <p>{this.state.data.createtime}</p>
                                </div>
                            </div>
                        </div>

                    </div>  
                </div>


                <div className="main">
                    <div className="cen">
                        <div className="box">
                            

                            <div className="tmb">

                                <div className="chead">
                                    <div className={this.state.ctype === 1?"citem c_active":"citem"} onClick={()=>{this.gotoChangeCtype(1)}}>
                                    作品详情
                                        <div className="icen"><span></span></div>
                                    </div>
                                </div>

                                <div className='cen'>
                                    <div className='tvideo'>
                                        <video className='video' controls src={this.state.data.video_text} />
                                    </div>
                                </div>

                                <div className="desc" hidden={this.state.ctype !== 1}>
                                    <div className="dinfo" dangerouslySetInnerHTML={{
                                            __html: this.state.data.remake
                                        }}></div>
                                </div>

                            </div>


                        </div>
                    </div>
                </div>

                <div className='alert' hidden={!this.state.alert}>
                    <div className='abox'>
                        <div className='cen'>
                            <img alt="" src="assets/imgs/chenggong.png" />
                        </div>
                        <h1>报名成功！</h1>
                        <p>您的在线报名已成功提交</p>
                        <p>我们管理员会及时和您联系</p>
                        <button onClick={()=>{this.setState({alert:false})}}>好的</button>
                    </div>
                </div>

                <Footer />
            </div>
        )
    }
}
